#ifndef _SOCKET_H_
#define _SOCKET_H_


typedef unsigned long SOCKET;
#define INVALID_SOCKET -1

#include <time.h>
//#include <stdio.h>
#include <string.h>

#include "sys_api.h"
#include "alog.h"

#define MAX_HOST_SIZE 128

///////////////////////////////////////////////

class Sockets
{
public:
    Sockets();
    virtual ~Sockets();

    virtual bool ConnectBySocket(SOCKET s);
    virtual bool Connect(const char *sHost, int nPort);

    virtual bool IsConnected();
    virtual bool IsError()
    {
        return ((m_nErrCode) ? true : false);
    };
    virtual void Close();

    virtual int Receive(char * pBuf, int nBufLen, int nFlags = 0);
    virtual int Send(const char * pBuf, int nBufLen, int nFlags = 0);

#ifdef WIN32
    virtual bool ShutDown(int nHow = SD_BOTH);
#else
    virtual bool ShutDown(int nHow = 2);
#endif

public:
    SOCKET      m_Socket;

    char        m_sHost[MAX_HOST_SIZE];
    int         m_nPort;

    bool        m_bConnected;
    int         m_nErrCode;
    /*  string      m_sErrMessage;*/
};


#endif
